package com.owen.oauth2.client.connect;

import org.springframework.social.oauth2.AccessGrant;
import org.springframework.social.oauth2.OAuth2Template;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

import java.util.Objects;

public class MyOAuth2Template extends OAuth2Template {

    public MyOAuth2Template(String clientId, String clientSecret) {
        super(clientId, clientSecret, "http://localhost:9000/oauth/authorize", "http://localhost:9000/oauth/token");
    }

    @Override
    public AccessGrant exchangeForAccess(String authorizationCode, String redirectUri, MultiValueMap<String, String> additionalParameters) {
        if(Objects.isNull(additionalParameters)) {
            additionalParameters = new LinkedMultiValueMap();
        }
        additionalParameters.add("scope","all");
        return super.exchangeForAccess(authorizationCode, redirectUri, additionalParameters);
    }
}
